package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeSubscriber;
import com.codegeek.project.slope.service.ISlopeSubscriberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订阅人Controller
 *
 * @author codegeek
 * @date 2020-02-04
 */
@RestController
@RequestMapping("/slope/subscriber")
@Api(value="推送管理Controller",tags={"用户管理推送管理操作接口"})
public class SlopeSubscriberController extends BaseController
{
    @Autowired
    private ISlopeSubscriberService slopeSubscriberService;

    /**
     * 查询订阅人列表
     */
    @ApiOperation("查询推送管理table列表")
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:list')")
    public TableDataInfo list(SlopeSubscriber slopeSubscriber)
    {
        startPage();
        List<SlopeSubscriber> list = slopeSubscriberService.selectSlopeSubscriberList(slopeSubscriber);
        return getDataTable(list);
    }

    /**
     * 导出订阅人列表
     */
    @ApiOperation("导出")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:export')")
    public AjaxResult export(SlopeSubscriber slopeSubscriber)
    {
        List<SlopeSubscriber> list = slopeSubscriberService.selectSlopeSubscriberList(slopeSubscriber);
        ExcelUtil<SlopeSubscriber> util = new ExcelUtil<SlopeSubscriber>(SlopeSubscriber.class);
        return util.exportExcel(list, "subscriber");
    }

    /**
     * 获取订阅人详细信息
     */
    @ApiOperation("获取推送管理详细信息")
    @GetMapping(value = "/{subscriberId}")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:getInfo')")
    public AjaxResult getInfo(@PathVariable("subscriberId") Long subscriberId)
    {
        return AjaxResult.success(slopeSubscriberService.selectSlopeSubscriberById(subscriberId));
    }

    /**
     * 新增订阅人
     */
    @ApiOperation("新增推送管理信息")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PreAuthorize("@ss.hasPermi('slope:subscriber:add')")
    public AjaxResult add(@RequestBody SlopeSubscriber slopeSubscriber)
    {
        return toAjax(slopeSubscriberService.insertSlopeSubscriber(slopeSubscriber));
    }

    /**
     * 修改订阅人
     */
    @ApiOperation("修改推送管理信息")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:edit')")
    public AjaxResult edit(@RequestBody SlopeSubscriber slopeSubscriber)
    {
        return toAjax(slopeSubscriberService.updateSlopeSubscriber(slopeSubscriber));
    }

    /**
     * 删除订阅人
     */
    @ApiOperation("删除推送管理信息")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
	@PostMapping("/{subscriberIds}")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:remove')")
    public AjaxResult remove(@PathVariable Long[] subscriberIds)
    {
        return toAjax(slopeSubscriberService.deleteSlopeSubscriberByIds(subscriberIds));
    }

    /**
     * 状态修改
     */
    @ApiOperation("推送人状态修改")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:changeStatus')")
    public AjaxResult changeStatus(SlopeSubscriber slopeSubscriber) {
        return toAjax(slopeSubscriberService.updateSlopeSubscriberStatus(slopeSubscriber));
    }

    /**
     * 批量禁用
     */
    @ApiOperation("批量禁用")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/selectedDisable")
    @PreAuthorize("@ss.hasPermi('slope:subscriber:selectedDisable')")
    public AjaxResult selectedDisable(@RequestBody List<Long> ids) {
        if (ids==null) {
            return null;
        }
        return toAjax(slopeSubscriberService.selectedDisable(ids));
    }
}
